package com.cskaoyan.service;

import lombok.Data;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.*;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

//@Data
public class UserServiceImpl implements UserService,
        BeanNameAware, BeanFactoryAware, ApplicationContextAware,
        InitializingBean, DisposableBean
{

    public UserServiceImpl() {
        System.out.println("1、Bean的实例化");
    }

    String parameter;

    public void setParameter(String parameter) {//property子标签
        System.out.println("2、设置属性值");
        this.parameter = parameter;
    }

    String beanName;
    BeanFactory beanFactory;
    ApplicationContext applicationContext;

    @Override
    public void sayHello() {
        System.out.println(beanName + ":学姐好");
    }

    @Override
    public void setBeanName(String name) {
        System.out.println("3、BeanNameAware的setBeanName方法");
        this.beanName = name;
    }
    @Override
    public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
        System.out.println("4、BeanFactoryAware的setBeanFactory方法");
        this.beanFactory = beanFactory;
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        System.out.println("5、ApplicationContextAware的setApplicationContext方法");
        this.applicationContext = applicationContext;
    }
    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println("7、InitializingBean的afterPropertiesSet方法");
    }

    //方法名可以任意写
    public void customInit() {
        System.out.println("8、自定义init方法");
    }


    public void customDestroy() {
        System.out.println("11、自定义的destroy");
    }

    @Override
    public void destroy() throws Exception {
        System.out.println("10、DisposableBean的destroy");
    }
}
